package com.atguigu.common.exception;

import com.atguigu.common.result.ResponseEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Alice
 * @since 2021-08-27 星期五 17:59
 */
@Data
@NoArgsConstructor
public class BusinessException extends RuntimeException {

  private Integer code;

  private String message;

  /**
   * @param message 错误消息
   */
  public BusinessException(String message) {
    this.message = message;
  }

  /**
   * @param code    错误码
   * @param message 错误消息
   */
  public BusinessException(Integer code, String message) {
    this.code = code;
    this.message = message;
  }

  /**
   * @param code    错误码
   * @param message 错误消息
   * @param cause   原始异常对象
   */
  public BusinessException(Integer code, String message, Throwable cause) {
    super(cause);
    this.message = message;
    this.code = code;
  }

  /**
   * @param resultCodeEnum 接收枚举类型
   */
  public BusinessException(ResponseEnum resultCodeEnum) {
    this.code = resultCodeEnum.getCode();
    this.message = resultCodeEnum.getMessage();
  }

  /**
   * @param resultCodeEnum 接收枚举类型
   * @param cause          原始异常对象
   */
  public BusinessException(ResponseEnum resultCodeEnum, Throwable cause) {
    super(cause);
    this.code = resultCodeEnum.getCode();
    this.message = resultCodeEnum.getMessage();
  }

}
